package com.zjjt.dc.modules.srv.service.lw.impl;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.zjjt.dc.modules.datacatch.entity.QueryCondition;
import com.zjjt.dc.modules.datacatch.service.IDataExportService;
import com.zjjt.dc.modules.srv.service.lw.ILWService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

@Service
public class LWService implements ILWService {

    @Autowired
    IDataExportService dataExportService;

    /**
     * 获取数据
     *
     * @param condition
     * @return
     */
    @Override
    public List<JSONObject> getDataByCondition(QueryCondition condition) {
        /**
         * 本功能为，从DataCatch中获取数据
         */
        if (condition == null) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Calendar now = Calendar.getInstance();
            Calendar start = Calendar.getInstance();
            start.add(Calendar.MONTH, -3);
            condition = new QueryCondition();
            condition.setBeginTime(sdf.format(start.getTime()));
            condition.setEndTime(sdf.format(now.getTime()));
        }

        JSONArray resultArray = dataExportService.getExportDataForLW(condition);

        return resultArray.toList(JSONObject.class);
    }
}
